import { Component, OnInit } from '@angular/core';
import { CveService } from 'src/app/core/service/cve.service';
import { LibraryService } from 'src/app/core/service/library.service';
import { LicenseService } from 'src/app/core/service/license.service';
import { ContainerService } from 'src/app/core/service/container.service';

@Component({
  selector: 'app-data-center-overview',
  templateUrl: './data-center-overview.component.html',
  styleUrls: ['./data-center-overview.component.scss']
})
export class DataCenterOverviewComponent implements OnInit {
  fileTypes = [
    {
      title: '组件',
      icon: 'component',
      total: 0,
      useCount: 0
    },
    {
      title: 'License',
      icon: 'shield_01',
      total: 0,
      useCount: 0
    },
    {
      title: '漏洞',
      icon: 'libs',
      total: 0,
      useCount: 0
    },
    {
      title: '容器基线',
      icon: 'datasource',
      total: 0,
      useCount: 0
    }
  ];
  data = [];
  constructor(
    private cveService: CveService,
    private libraryService: LibraryService,
    private licenseService: LicenseService,
    private containerService: ContainerService,
  ) { }

  getCVECount(): void {
    this.cveService.getCVEConut()
      .subscribe((CVEConut) => {
        console.log(`===收到json数据===> ${CVEConut}`);
        this.fileTypes[2].total = CVEConut.total;
        this.fileTypes[2].useCount = CVEConut.useCount;
        console.log(CVEConut.total, CVEConut.useCount);
      });
  }

  getLibCount(): void {
    this.libraryService.getLibraryCount()
      .subscribe((LibConut) => {
        console.log(`===收到json数据===> ${LibConut}`);
        this.fileTypes[0].total = LibConut.totalNum;
        this.fileTypes[0].useCount = LibConut.usedNum;
        console.log(LibConut.totalNum, LibConut.usedNum);
      });
  }

  getLicenseCount(): void {
    this.licenseService.getLicenseCount()
      .subscribe((LicenseCount) => {
        console.log(`===收到json数据===> ${LicenseCount}`);
        this.fileTypes[1].total = LicenseCount.totalNum;
        this.fileTypes[1].useCount = LicenseCount.usedNum;
        console.log(LicenseCount.totalNum, LicenseCount.usedNum);
      });
  }

  getCount(): void {
    this.containerService.getCount()
      .subscribe((Count) => {
        console.log(`===收到json数据===> ${Count}`);
        this.fileTypes[3].total = Count.containerCount;
        this.fileTypes[3].useCount = Count.baseLineCount;
        console.log(Count.containerCount, Count.baseLineCount);
      });
  }

  ngOnInit() {
    this.getCVECount();
    this.getLibCount();
    this.getLicenseCount();
    this.getCount();
  }

}
